package com.dd.shop4j.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间公用类
 * @author Administrator
 *
 */
public class DateUtils {

	private static final DateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
	private static final DateFormat yyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	private static final DateFormat yyyyMMddHHmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public static String getYmd(Date date) {
		return yyyyMMdd.format(date);
	}
	
	public static Date parseYmd(String dateStr) {
		try {
			return yyyyMMdd.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getYmdHmi(Date date) {
		return yyyyMMddHHmm.format(date);
	}
	
	public static Date parseYmdHmi(String dateStr) {
		try {
			return yyyyMMddHHmm.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getYmdHmis(Date date) {
		return yyyyMMddHHmmss.format(date);
	}
	
	public static Date parseYmdHmis(String dateStr) {
		try {
			return yyyyMMddHHmmss.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
}
